Skip to content

Fix: commonizable PlatformMutex on native (#329) - #330

Merged
b-re-w merged 1 commit into
developfrom
feat/native-mutex-commonized
Oct 25, 2026
Merged

b-re-w merged 1 commit into
developfrom
feat/native-mutex-commonized

Conversation

@b-re-w

@b-re-w b-re-w commented Oct 25, 2026

Copy link
Copy Markdown
Member

Closes #329

  • Cause: PlatformMutex.native.kt (HandleTable mutated without the GIL via _pm_release (suspected race) #117, Binder: HandleTable owns a mutex (#117) #302) called pthread_mutex_init, which is not in the POSIX surface Kotlin/Native commonizes across Apple and Linux. :python-multiplatform:compileNativeMainKotlinMetadata, which publishAllToMavenLocal runs, therefore failed. The per-target compiles passed, so the regression went unnoticed.
  • Fix: a non-recursive CAS spin lock on kotlin.concurrent.atomics.AtomicInt, the same common atomics PyType uses. PlatformMutex's contract keeps critical sections to a few array and counter operations and never calls Python, so spinning is bounded and cannot hold up a stop-the-world pause.
  • Red: with the old file, compileNativeMainKotlinMetadata fails with 'Unresolved reference pthread_mutex_init'.
  • Green: compileNativeMainKotlinMetadata, compileKotlinIosSimulatorArm64 and compileKotlinAndroidNativeArm64 pass. iosSimulatorArm64Test (HandleTable and GilReleaseNativeTest) passes 16/16.

…Main metadata compiles again (#329)

pthread_mutex_init is not in the POSIX surface Kotlin/Native commonizes across Apple and Linux, so
compileNativeMainKotlinMetadata (which publishing runs) failed although every per-target compile
passed. The critical sections are a few array operations and never call Python, so a CAS spin lock
is bounded.
@b-re-w
b-re-w merged commit ab34869 into develop Oct 25, 2026
@b-re-w
b-re-w deleted the feat/native-mutex-commonized branch October 25, 2026 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant